package com.ztstkj.lzservices.cameras

import android.content.Context
import android.content.pm.PackageManager
import android.hardware.camera2.CameraAccessException
import android.hardware.camera2.CameraManager
import com.sscl.baselibrary.utils.DebugUtil

object CameraUtil {
    /**
     * 一直是true
     */
    fun isCamera(context: Context): Boolean {
        return context.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
    }

    fun isCamera2(context: Context): Boolean {
        val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
        return try {
            cameraManager.cameraIdList.isNotEmpty() // 检查是否有至少一个摄像头ID
        } catch (e: CameraAccessException) {
            DebugUtil.errorOut(e.message.toString())
            false // 捕获异常意味着访问失败或无权限
        }
    }
}